package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by AD on 2016/5/12.
 */
@HttpInlet(Conn.INLET_GET_4SLIST)
public class Get4SShopList extends JTAsyGet<Get4SShopList.Info> {
    public String token = JTApplication.jtPreferences.readToken();
    public String obdId = JTApplication.jtPreferences.readOdbID();

    public Get4SShopList(AsyCallBack<Info> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        info.code = head.optString("code");

        JSONObject body = apiTYF.optJSONObject("body");

        JSONArray fSlist = body.optJSONArray("4Slist");



        if(fSlist!=null){
            for (int i=0;i<fSlist.length();i++){
                JSONObject object_4s = fSlist.optJSONObject(i);
                FSList fsList = new FSList();
                fsList.ID = object_4s.optString("id");
                fsList.NAME = object_4s.optString("name");
                fsList.REMARK = object_4s.optString("remark");
                fsList.PID = object_4s.optString("pid");
                fsList.STATE = object_4s.optString("state");
                fsList.LON = object_4s.optString("lon");
                fsList.LAT = object_4s.optString("lat");
                fsList.ADDRESS = object_4s.optString("address");
                fsList.PHONE = object_4s.optString("phone");
                fsList.LOGO = object_4s.optString("logo");
                fsList.AREAID = object_4s.optString("areaid");
                fsList.AREANAME = object_4s.optString("areaname");
                fsList.PRIORITY = object_4s.optString("priority");
                info.fSList.add(fsList);
            }

            JSONArray areaarr = body.optJSONArray("arealist");
            if(areaarr!=null){
                for(int i=0;i<areaarr.length();i++){
                    JSONObject obj_area = areaarr.optJSONObject(i);
                    AreaList areaList = new AreaList();
                    areaList.AREAID = obj_area.optString("AREAID");
                    areaList.AREANAME = obj_area.optString("AREANAME");
                    if(areaList.AREAID.equals("0")){
                        areaList.FLAG="1";
                    }else{
                        areaList.FLAG="0";
                    }

                    info.arList.add(areaList);
                }
            }

            JSONArray maparr = body.optJSONArray("mapList");
            if(maparr!=null){
                for(int i=0;i<maparr.length();i++){
                    JSONObject obj_map = maparr.optJSONObject(i);
                    AreaList mapList = new AreaList();
                    mapList.AREAID = obj_map.optString("ID");
                    mapList.AREANAME = obj_map.optString("NAME");
                    if(mapList.AREAID.equals("6003")){
                        mapList.FLAG="1";
                    }else{
                        mapList.FLAG="0";
                    }
                    info.mapList.add(mapList);
                }

            }
        }else{
            TOAST = "暂无4S店提供预约";
        }
        return info;
    }

    public static class Info{
        public String msg;
        public String code;
        public List<FSList> fSList = new ArrayList<>();
        public List<AreaList> arList = new ArrayList<>();
        public List<AreaList> mapList = new ArrayList<>();

    }
    public static class FSList implements Serializable{
        public String  ID,NAME,REMARK,PID,STATE,LON,LAT,ADDRESS,PHONE,LOGO,AREAID,AREANAME,PRIORITY;
        public double DISTANCE;
    }

    public static class AreaList implements Serializable{
        public String AREAID,AREANAME,FLAG;
    }

//    public static class MapList implements  Serializable{
//        public String NAME,ID;
//
//    }
}
